package leetcode.sort;

import java.util.Arrays;

public class SelectSort {
    public int[] select_sort(int[] sourceArray) {
        int[] arr = Arrays.copyOf(sourceArray, sourceArray.length);

        for (int i = 0; i < arr.length - 1; i++) {
            int min = i;

            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }

            if (i != min) {
                int tmp = arr[i];
                arr[i] = arr[min];
                arr[min] = tmp;
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        SelectSort selectSort = new SelectSort();
        int[] arr = new int[]{1, 3, 5, 7, 3, 9, 6, 3};
        int[] ret = selectSort.select_sort(arr);
        for (int i : ret) {
            System.out.print(i + " ");
        }
    }
}
